package jframe;

import javax.swing.*;
import java.awt.*;

/**
 * Created by User on 2018/1/2.
 */
public class App {
    public static void main(String[] args) {

        new TestJFrame("first JFrame demo");

    }

    static class TestJFrame extends JFrame {

        Container container;

        public TestJFrame(String title) {
            super(title);
            container = getContentPane();
            setSize(500, 500);
            centerOnScreen();   //窗体在屏幕中间显示
            container.setBackground(new Color(165, 79, 90));  //设置窗体背景色
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);   //设置关闭按钮操作
            setVisible(true);   //设置窗体可见
        }

        public void centerOnScreen() {
            Dimension displaySize = getToolkit().getScreenSize();
            Dimension winSize = getSize();
            int x = (displaySize.width - winSize.width) / 2;
            int y = (displaySize.height - winSize.height) / 2;
            if (x < 0) {
                x = 0;
            }
            if (y < 0) {
                y = 0;
            }
            setLocation(x, y);
        }
    }
}
